package com.xjust.controller.registerDepartMent;

import com.xjust.pojo.ResponseData;
import com.xjust.pojo.Result;
import com.xjust.pojo.ResultBean;
import com.xjust.service.RegisterService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.math.BigDecimal;
import java.security.PublicKey;
import java.time.LocalDateTime;
import java.util.Collections;
import java.util.List;
import java.util.Map;

@CrossOrigin
@RestController
@RequestMapping("/registers")
public class RegisterController {
    @Autowired
    RegisterService registerService;
    //获取最大病历号
    @GetMapping("/getMaxCaseNumber")
    public Result gerMaxCaseNumber(){
        return Result.success(registerService.getMaxCaseNumber());
    }
    @GetMapping("/getDoctorUsedNumber")
    public Result getDoctorUsedNumber(Integer doctorId){
        Integer i = registerService.getDoctorUsedNumber(doctorId);
        System.out.println(i);
        return Result.success(i);
    }
    //提交挂号信息
    @PostMapping("/saveRegister")
    public Result saveRegister(@RequestBody Map<String,Object> register){
        registerService.saveRegister(register);
        return Result.success();
    }
    //获取已看诊患者人数
    @GetMapping("/getFinishPatientCount")
    public Integer getFinishPatientCount(Integer employeeId){
        return registerService.getFinishPatientCount(employeeId);
    }
    //获取等待患者人数
    @GetMapping("/getWaitPatientCount")
    public Integer getWaitPatientCount(Integer employeeId){
        return registerService.getWaitPatientCount(employeeId);
    }
    @GetMapping("/getWaitPatient")
    public ResultBean getWaitPatient(
            Integer employeeId,
           @RequestParam(defaultValue = "1") Integer page,
           @RequestParam(defaultValue = "5") Integer pageSize,
           String caseNumber,
           String realName, Integer visitState
    ){
        return registerService.getWaitPatient(employeeId,page,pageSize,caseNumber,realName,visitState);
    }
    @GetMapping("/getPatient")
    public ResultBean getPatient(
            @RequestParam(defaultValue = "1") Integer page,
            @RequestParam(defaultValue = "5") Integer pageSize,
            String caseNumber,
            String realName
    ){
        return registerService.getPatient(page,pageSize,caseNumber,realName);
    }
    //收费患者查看界面
    @GetMapping("/getTollPatient")
    public Result getPatient(Integer employeeId, String caseNumber, String realName) {
        ResponseData responseData = registerService.getPatientToToll(employeeId, caseNumber, realName);
        if (responseData != null) {
            return Result.success(responseData);
        } else {
            return Result.error("Patient not found"); // 或者根据具体情况返回错误信息
        }
    }
    //提交所有收费项目并且改变对应状态
    @PutMapping("/settlement")
    public Result settlement(@RequestBody List<Map<String,Object>> tableData){
        registerService.settlement(tableData);
        return Result.success();
    }

    //检查管理获取挂号人员信息
    @GetMapping("/getPatientInfo")
    public List<Map<String,Object>> getPatientInfo(String techType,String case_number,String real_name){
        return registerService.getPatientAll(techType,case_number,real_name);
    }

}
